layui.use(['table', 'admin', 'ax', 'func'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;

    /**
     * 消息提醒
     */
    var btyPaymentOrderDetailsSendMsg = {
        tableId: "btyPaymentOrderDetailsSendMsgTable"
    };

    /**
     * 初始化表格的列
     */
    btyPaymentOrderDetailsSendMsg.initColumn = function () {
        return [[
            // {type: 'checkbox'},
            {field: 'id', sort: true, title: '序号',align: "center", fixed: true,type:'numbers'},
            // {field: 'id', hide: true, title: '主键id'},
            // {field: 'yybbId', sort: true, title: '日现金表id'},
            {field: 'dianming', sort: true, title: '店名'},
            // {field: 'dm', sort: true, title: '店名'},
            // {field: 'yaoma', sort: true, title: '妖码'},
            {field: 'yaoma', sort: true, title: '妖码'},
            {field: 'kqDz', sort: true, title: '店长'},
            // {field: 'payCode', sort: true, title: '支付编号'},
            // {field: 'btyPaymentOrderId', sort: true, title: '支付订单表id'},
            // {field: 'payState', sort: true, title: '支付状态（0.支付中，1，支付成功，2支付失败）'},
            {field: 'kqDh', sort: true, title: '电话'}
            // {field: 'createTime', sort: true, title: '创建时间'},
            // {field: 'createUser', sort: true, title: '创建人'},
            // {field: 'updateTime', sort: true, title: '修改时间'},
            // {field: 'updateUser', sort: true, title: '修改人'},
            // {align: 'center', toolbar: '#tableBar', title: '操作'}
        ]];
    };

    var startDateTime= $("#startDateTime").val();
    var endDateTime= $("#endDateTime").val();
    var cashBalance= $("#cashBalance").val();
    var xjHave= $("#xjHave").val();
    var xjbzHave= $("#xjbzHave").val();
    var dm= $("#dm").val();
    var startbpoPayDatetime= $("#startbpoPayDatetime").val();
    var endbpoPayDatetime= $("#endbpoPayDatetime").val();

    //点击提交按钮
    btyPaymentOrderDetailsSendMsg.sendMessage = function(){

            var queryData = {};
            queryData["startDateTime"] = startDateTime;
            queryData["endDateTime"] = endDateTime;
            queryData["cashBalance"] = cashBalance;
            queryData["xjHave"] = xjHave;
            queryData["xjbzHave"] = xjbzHave;
            queryData["dm"] = dm;

            $.ajax({
                type: "post",
                url: "/btyPaymentOrderDetails/xjjzPushMsgToIMAndWx",
                datatype: "json",
                async: false,
                data:queryData,
                success: function (data) {
                    if(data.success == true){
                        Feng.success("消息发送成功!");
                    }else{
                        Feng.error(data.message);
                    }
                    console.log(data);
                    debugger
                    //传给上个页面，刷新table用
                    admin.putTempData('formOk', true);
                    //关掉对话框
                    admin.closeThisDialog();

                },
                error: function (data) {
                    Feng.error("消息发送失败!");
                }
            });
    };

    /**
     * 点击查询按钮
     */
    btyPaymentOrderDetailsSendMsg.search = function () {
        var queryData = {};

        queryData["startDateTime"] = startDateTime;
        queryData["endDateTime"] = endDateTime;
        queryData["cashBalance"] = cashBalance;
        queryData["xjHave"] = xjHave;
        queryData["xjbzHave"] = xjbzHave;

        table.reload(btyPaymentOrderDetailsSendMsg.tableId, {
            where: queryData
        });
    };

    /**
     * 跳转到添加页面
     */
    btyPaymentOrderDetailsSendMsg.jumpAddPage = function () {
        window.location.href = Feng.ctxPath + '/btyPaymentOrderDetails/add'
    };

    /**
    * 跳转到编辑页面
    *
    * @param data 点击按钮时候的行数据
    */
    btyPaymentOrderDetailsSendMsg.jumpEditPage = function (data) {
        window.location.href = Feng.ctxPath + '/btyPaymentOrderDetails/edit?id=' + data.id
    };

    /**
     * 导出excel按钮
     */
    btyPaymentOrderDetailsSendMsg.exportExcel = function () {
        var checkRows = table.checkStatus(btyPaymentOrderDetails.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };



    // // 渲染表格
    // var tableResult = table.render({
    //     elem: '#' + btyPaymentOrderDetailsSendMsg.tableId,
    //     url: Feng.ctxPath + '/btyPaymentOrderDetails/list',
    //     page: true,
    //     height: "full-158",
    //     cellMinWidth: 100,
    //     cols: btyPaymentOrderDetailsSendMsg.initColumn()
    // });

    var tableResult = table.render({
        elem: '#' + btyPaymentOrderDetailsSendMsg.tableId,
        url: Feng.ctxPath + '/btyPaymentOrderDetails/searchCashBalance2',
        where: {
            startDateTime: startDateTime,
            endDateTime:endDateTime,
            cashBalance:cashBalance,
            xjHave:xjHave,
            xjbzHave:xjbzHave,
            dm:dm
        },
        height:450,
        cellMinWidth: 100,
        limit:Number.MAX_VALUE,
        cols: btyPaymentOrderDetailsSendMsg.initColumn(),
        done:function (res,curr,count) {
            if (res.count==0){
                $("#send").attr("disabled",true)
            }
        }
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        btyPaymentOrderDetailsSendMsg.search();
    });

    // 添加按钮点击事件
    $('#btnAdd').click(function () {

        btyPaymentOrderDetailsSendMsg.jumpAddPage();

    });

    // 导出excel
    $('#btnExp').click(function () {
        btyPaymentOrderDetailsSendMsg.exportExcel();
    });

    // 提交
    $('#send').click(function () {
        btyPaymentOrderDetailsSendMsg.sendMessage();
    });

    // 工具条点击事件
    table.on('tool(' + btyPaymentOrderDetailsSendMsg.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'edit') {
            btyPaymentOrderDetailsSendMsg.jumpEditPage(data);
        } else if (layEvent === 'delete') {
            btyPaymentOrderDetailsSendMsg.onDeleteItem(data);
        }
    });
    //初始化页面
    $(function () {

        setTimeout(() =>{
            btyPaymentOrderDetailsSendMsg.search();
        },100);

    });
});
